package com.springlistener;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationEvent;
import org.springframework.context.ApplicationEventPublisher;
import org.springframework.stereotype.Component;

/**
 * @Author Fizz Pu
 * @Date 2021/4/28 下午7:40
 * @Version 1.0
 * 失之毫厘，缪之千里！
 */

@Component
public class Publisher {

    private Logger logger = LoggerFactory.getLogger(this.getClass());

    @Autowired
    private ApplicationEventPublisher publisher;

    public void publishEvent(ApplicationEvent event) {
        if(event == null){
            throw new IllegalArgumentException();
        }
        logger.debug("发布事件{}", event);
        publisher.publishEvent(event);
    }
}
